Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mdopt

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdopt

markdown option parsing

  • 2.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

mdopt

markdown option parsing

Useful in combination with marked-man to ensure your man pages are always up to date by making the docs a core part of the cli's runtime. (related: package.json man).

Check out the test cases, or view the example below to get an idea of what a properly formatted options section looks like.

Example

cli.js:

const mdopt = require('mdopt');

const { readFileSync } = require('fs');

const md = readFileSync('path.md', {
  encoding: 'utf8'
});

const argv = process.argv.slice(2)

const argv = mdopt(argv, md);

console.log(argv);

argv is a variable that holds a minimist object that has been populated (aliases, defaults) according to the provided markdown file.

A sample session might look like this:

$ node cli.js
Error: Missing required option demand

$ node cli.js --demand
Error: Missing required option pghost

$ PGHOST=localhost node demo.js --demand hey hey you you
{ _: [ 'hey', 'hey', 'you', 'you' ],
  f: false,
  flag: false,
  home: '/home/jay',
  demand: true,
  default: 'foo',
  d: 'foo',
  pghost: 'localhost' }

And finally what the spec.md file looks like demonstrating all available options:

spec.md

# demo -- A demonstration of the features & formatting

## SYNOPSIS

sample [flags] `<first>` `<last>` `[pet]`

## OPTIONS

### -f, --flag

This is a boolean flag as there is no values that
follow the flag.  It can be accessed with $('f') or
$('flag')

### --anything ANYTHING

This flag expects a value to come after it. It can be a
number, a string, etc. The type will be auto detected
and the value of $('anything') will be that value.

### -s "VALUE", --string "VALUE"

Same as above, except that the value placeholder is in
quotes meaning that no type detection is performed, and
it is kept as a string. Give it `000123` and it will
remain `000123` vs. converting it to a number resulting
in `123`.

### --default=SOMETHING, -d SOMETHING (default=foo)

It is also possible to set default values.

### --home (default=$HOME)

And use environment variables to set those
defaults. Any default value beginning with a `$` will
be treated as an environment variable.

### --demand (required)

We can also demand that a flag should be set.

### --pghost "URI" (required, default=$PGHOST)

Combining required and using environment variables as
defaults is a good way to ensure that the value will be
set one way or another.

## AUTHORS

... Another section

## BUGS

... Another section. Add as many sections as you want.

Keywords

FAQs

Package last updated on 05 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc